/*跨越问题的解决*/
var http = require('http');
var fs = require('fs');
let querystring = require('querystring');
var url = require('url');

// 创建服务器
http.createServer( function (request, response) {


      /**
     *    localhost:8080/login.html
       *
       *     post  action = 'localhost:3000/login'
       *        username
       *        password
       *        btn
     *    * **/

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader('Access-Control-Allow-Headers', 'Content-type');
    response.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS,PATCH");

    // 解析请求，包括文件名
    var pathname = url.parse(request.url).pathname;

    pathname = pathname.substr(1);

    console.log(pathname);

    // 输出请求的文件名
    console.log("Request for " + pathname + " received.");


    let urlObject = url.parse(request.url, true);
    console.log(urlObject);
  /*  let str= urlObject.query.callback
        +'('+JSON.stringify({"msg":"success"})+')';*/

    response.end(JSON.stringify({"msg":"success"}));


}).listen(3000);

// 控制台会输出以下信息
console.log('Server running at http://127.0.0.1:3000/');